package com.guigu.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.guigu.health.pojo.CheckGroupResult;
import com.guigu.health.pojo.CheckItem;
import com.guigu.health.pojo.Setmeal;
import com.guigu.health.pojo.SetmealExample;
import com.guigu.health.service.CheckGroupService;
import com.guigu.health.service.SetmealService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName:PageController
 * @Description:主页控制层
 * @Author:longtao
 * @Date:2021/3/24
 * @Version:1.0
 */
@Controller
public class PageController {
    /**
     * 检查组
     */
    @Reference
    public CheckGroupService checkGroupService;
    /**
     * 套餐
     */
    @Reference
    public SetmealService setmealService;

    /**
     * 显示检查项
     *
     * @param request
     * @return
     * @throws UnsupportedEncodingException
     * @throws JsonProcessingException
     */
    @ResponseBody
    @RequestMapping(value = "/queryAll", produces = {"application/json;charset=UTF-8"})
    public Object queryAllCheckGroup(HttpServletRequest request) throws UnsupportedEncodingException, JsonProcessingException {
        List<CheckGroupResult> list = checkGroupService.queryCheckGroupAllList();
        return list;
    }

    /**
     * 根据id查询检查项
     *
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "queryCheckItemID", produces = {"application/json;charset=UTF-8"})
    public Object queryCheckItem(String id) {
        Integer cid=0;
        if ("".equals(id) || id == null) {
         id=String.valueOf(cid);
        }
        List<CheckItem> list = checkGroupService.queryCheckItemAll(Integer.valueOf(id));
        return list;
    }

    @ResponseBody
    @RequestMapping(value = "/showPackages", produces = {"application/json;charset=UTF-8"})
    public Object showPackages() {
        SetmealExample example=new SetmealExample();
        SetmealExample.Criteria criteria=example.createCriteria();
        List<Setmeal> list = setmealService.selectByExample(example);
        return list;
    }


}
